package org.example.DesignPatterns.Observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: farprt
 * @create: 2022-09-25 13:25
 **/
public class Shop {

    private String product;
    private List<Buyer> buyers;

    public Shop() {
        this.product="无商品";
        this.buyers=new ArrayList<>();
    }

    public void register(Buyer buyer){
        this.buyers.add(buyer);
    }

    public String getProduct(){
        return product;
    }

    public void setProduct(String product){
        this.product=product;
        notifyBuyers();
    }

    public void notifyBuyers(){
        buyers.stream().forEach(buyer -> buyer.inform(this.getProduct()));
    }

}